import pymysql
import random


def getDishes():
    # 连接数据库
    conn = pymysql.connect(host="localhost", user="root", password="123456", database="esl", charset="utf8mb4")
    cursor = conn.cursor()

    try:
        # 执行查询（随机选择 3 个菜品）

        query = "SELECT dish_id,canteen_id FROM dish"
        cursor.execute(query)

        # 获取数据
        dishes = cursor.fetchall()
        return dishes
    except Exception as e:
        print(f"数据库查询出错: {e}")

    finally:
        # 关闭连接
        cursor.close()
        conn.close()


if __name__ == "__main__":
    dishes = getDishes()
    for dish in dishes:
        print(dish)
